package com.xianye.erp.controller.base;

import javax.servlet.http.HttpServletRequest;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.servlet.ModelAndView;
import com.xianye.erp.util.PageData;
import com.xianye.erp.util.UuidUtil;

/**
 * 修改时间：2015、12、11
 */
@Controller
public class BaseController {
	
	@Autowired
	private JdbcTemplate jdbc;

	public  JSONObject getError(){
		JSONObject obj = new JSONObject();
		obj.put("api_status", "exception");
		return obj;
	}
	/** new PageData对象
	 * @return
	 */
	public PageData getPageData(){
		return new PageData(this.getRequest());
	}
	
	/**得到ModelAndView
	 * @return
	 */
	public ModelAndView getModelAndView(){
		return new ModelAndView();
	}
	
	/**得到request对象
	 * @return
	 */
	public HttpServletRequest getRequest() {
		HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
		return request;
	}

	/**得到32位的uuid
	 * @return
	 */
	public String get32UUID(){
		return UuidUtil.get32UUID();
	}

	public  String returnJSON(boolean flag, String msg, Object data){
		JSONObject json = new JSONObject();
		json.accumulate("flag", flag);
		json.accumulate("msg", msg);
		json.accumulate("data", data);
		System.out.println(json.toString());
		return json.toString();
	}
	

}
